import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)

/**
 * This class defines a crab. Crabs live on the beach.
 */
public class Crab extends Animal
{

private int countWorms;

    public void act()
    {
        //move();
        if ( atWorldEdge() ){
                  turn(45);
            }
        
        if ( canSee(Worm.class ) ){
            eat(Worm.class);
            countWorms++;
            getWorld().addObject(new Worm(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(500));
        }
        if ((Greenfoot.isKeyDown("up"))) 
            move();
        if ((Greenfoot.isKeyDown("left"))) 
            turn(5);
        if ((Greenfoot.isKeyDown("right"))) 
            turn(-5);
        
        if (canSee(Trash.class)){
            eat(Trash.class);
            countWorms = 0;
        }
    }
    public void wormsEaten()
    {
        System.out.println(countWorms);
    }


    
}


